﻿@model Family

@{
    IEnumerable<Person> familyMembers = new[] {
        new Person{FirstName ="Martin", LastName="Strimpfl"},
        new Person{FirstName = "Jakub", LastName="Strimpfl"},
        new Person{FirstName = "Jan", LastName = "Strimpfl"},
        new Person{FirstName = "Anezka", LastName = "Strimpflova"},
        new Person{FirstName = "Pavla", LastName = "Strimpflova"}
    };
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Family</title>
</head>
<body>
    <div> 
        @using (Html.BeginForm())
        {
            foreach (var member in familyMembers)
            {
                var index = Guid.NewGuid().ToString();

                <input type="checkbox" value="@index" name="members.index" @Checked(member) />@member.FirstName@: @member.LastName<br />


    <input type="hidden" value="@member.FirstName" name="members[@index].FirstName" />
    <input type="hidden" value="@member.LastName" name="members[@index].LastName" />
            }
            <input type="submit" />
        }
    </div>
</body>
</html>
@helper Checked(Person person)
{
    if (this.Model.Members.Any(m => m.FirstName.Equals(person.FirstName) && m.LastName.Equals(person.LastName)))
    {
        @:checked="checked"
    }
}